#include <bits/stdc++.h>
using namespace std;
const int M = 100005;
int t,n,m,l,lv,ans1 = 0,ans2 = 0;
int d[M],v[M],a[M],p[M],tmp1 = M,tmp2 = 0;
bool checka = 1,checkb = 1;
int main()
{
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    cin>>t;
    for (int k = 1; k <= t; k++)
    {
        ans1 = 0;
        cin>>n>>m>>l>>lv;
        for (int i = 1; i <= n; i++)
        {
            cin>>d[i]>>v[i]>>a[i];
        }
        for (int i = 1; i <= m; i++)
        {
            cin>>p[i];
        }
        sort(p + 1, p + m + 1);
        for (int i = 1; i <= n; i++)
        {
            if (a[i] == 0)
            {
                checkb = 0;
                if (v[i] > lv && d[i] <= p[m])
                {
                    ans1++;
                }
            }
            else if (a[i] > 0)
            {
                checka = 0;
                double s = (lv * lv - v[i] * v[i]) / (2.0 * a[i]) + d[i];
                if (v[i] > lv || (s <= p[m] && s >= p[1]))
                {
                    ans1++;
                    int j = 1;
                    for (; j <= m && s <= p[j]; j++) {}
                    tmp1 = min(tmp1,j);
                }
            }
            else
            {
                checka = 0;
                checkb = 0;
                double s = (lv * lv - v[i] * v[i]) / (2.0 * a[i]) + d[i];
                if (v[i] > lv)
                {
                    bool flag = false;
                    for (int j = 1; j <= m; j++)
                    {
                        if (d[i] <= p[j] && p[j] < s)
                        {
                            flag = true;
                            break;
                        }
                    }
                    if (flag)
                    {
                        ans1++;
                        int j = 1;
                        for (; j <= m && s >= p[j]; j++) {}
                        tmp2 = max(tmp2,j - 1);
                    }
                }
            }
        }
        cout<<ans1<<" ";
        if (checka || checkb)
        {
            ans2 = 1;
        }
        else if (ans1 == 0)
        {
            ans2 = m;
        }
        else if (tmp1 == m || tmp1 == 0)
        {
            ans2 = m - 1;
        }
        else if (tmp1 > tmp2)
        {
            ans2 = m - 2;
        }
        else
        {
            ans2 = m - 1;
        }
        cout<<ans2<<endl;

    }
    return 0;
}
